<?php

/**
 * This is the model class for table "kecamatan".
 *
 * The followings are the available columns in table 'kecamatan':
 * @property integer $kc_id
 * @property string $nama
 * @property string $camat
 *
 * The followings are the available model relations:
 * @property Curahhujanperbulan[] $curahhujanperbulans
 * @property Luastanah[] $luastanahs
 * @property Luastanahnonpertanian[] $luastanahnonpertanians
 * @property Luastanahnonsawah[] $luastanahnonsawahs
 * @property Luastanahpertanian[] $luastanahpertanians
 * @property Luastanahsawahirigasi[] $luastanahsawahirigasis
 * @property Luastanahsawahirigasidesa[] $luastanahsawahirigasidesas
 * @property Luastanahsawahirigasisederhana[] $luastanahsawahirigasisederhanas
 * @property Luastanahsawahirigasisemiteknis[] $luastanahsawahirigasisemiteknises
 * @property Luastanahsawahirigasiteknis[] $luastanahsawahirigasiteknises
 * @property Luastanahsawahtadahhujan[] $luastanahsawahtadahhujans
 * @property Tinggicurahhujan[] $tinggicurahhujans
 */
class Kecamatan extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Kecamatan the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'kecamatan';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('nama, camat', 'length', 'max'=>128),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('kc_id, nama, camat', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'curahhujanperbulans' => array(self::HAS_MANY, 'Curahhujanperbulan', 'id_kecamatan'),
			'luastanahs' => array(self::HAS_MANY, 'Luastanah', 'id_kecamatan'),
			'luastanahnonpertanians' => array(self::HAS_MANY, 'Luastanahnonpertanian', 'id_kecamatan'),
			'luastanahnonsawahs' => array(self::HAS_MANY, 'Luastanahnonsawah', 'id_kecamatan'),
			'luastanahpertanians' => array(self::HAS_MANY, 'Luastanahpertanian', 'id_kecamatan'),
			'luastanahsawahirigasis' => array(self::HAS_MANY, 'Luastanahsawahirigasi', 'id_kecamatan'),
			'luastanahsawahirigasidesas' => array(self::HAS_MANY, 'Luastanahsawahirigasidesa', 'id_kecamatan'),
			'luastanahsawahirigasisederhanas' => array(self::HAS_MANY, 'Luastanahsawahirigasisederhana', 'id_kecamatan'),
			'luastanahsawahirigasisemiteknises' => array(self::HAS_MANY, 'Luastanahsawahirigasisemiteknis', 'id_kecamatan'),
			'luastanahsawahirigasiteknises' => array(self::HAS_MANY, 'Luastanahsawahirigasiteknis', 'id_kecamatan'),
			'luastanahsawahtadahhujans' => array(self::HAS_MANY, 'Luastanahsawahtadahhujan', 'id_kecamatan'),
			'tinggicurahhujans' => array(self::HAS_MANY, 'Tinggicurahhujan', 'id_kecamatan'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'kc_id' => 'Kc',
			'nama' => 'Kecamatan',
			'camat' => 'Camat',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('kc_id',$this->kc_id);
		$criteria->compare('nama',$this->nama,true);
		$criteria->compare('camat',$this->camat,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	public static function dropDown(){
		$model = Kecamatan::model()->findAll();
		$result = array();
		foreach($model as $m){
			$result[$m->kc_id]=$m->nama;
		}
		return $result;
	}
}